import sys
import shutil
import cppAnalyze

class CopyPlugin(cppAnalyze.Plugin):
        def __init__(self):
                cppAnalyze.Plugin.__init__(self)
                self.pluginName = 'copy'
                self.pluginDescription = 'Copies source files from an existing directory. ' \
                        'Does not use any SCC provider at all. Useful for smaller projects, or in situations where the source is already available.'

        def getConfigSettings(self):
                return 'srcDir,string'

        def processPluginOptions(self, argv):
                if not argv:
                        print 'Invalid plugin options. Expecting --dstDir <path>.'
                        return False
                
                if '--dstDir' in argv:
                        dstDirIndex = argv.index('--dstDir') + 1

                        if dstDirIndex >= len(argv):
                                print 'Error: No dstDir was specified.'
                                return False
                        else:
                                self.dstDir = argv[dstDirIndex]
                                return True

                return False

        def makeStuffGoNow(self):
                srcDir = self.getSetting('srcDir')

                if not srcDir:
                        print 'Error: No srcDir was specified in the config-file.'
                        return -1

                srcDir = str(srcDir.toString())
                # remove old tree first!
                shutil.rmtree(self.dstDir,True)
                shutil.copytree(srcDir, self.dstDir)

                print 'Copied: %s -> %s' % (srcDir, self.dstDir)

if __name__ == '__main__':
        exit(CopyPlugin().runPlugin())

